package com.ynwt.service;

import com.alibaba.fastjson.JSON;
import com.github.sd4324530.fastweixin.api.MenuAPI;
import com.github.sd4324530.fastweixin.api.entity.Menu;
import com.github.sd4324530.fastweixin.api.enums.ResultType;
import org.apache.commons.io.FileUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.io.File;
import java.io.InputStream;

/**
 * Created by huangying on 2017/4/26.
 */
@Service
public class WeixinManagerServiceImpl implements WeixinManagerService{
    /**
     * 删除菜单
     */
    @Override
    public void deleteMenu() {
        menuAPI.deleteMenu();
    }

    /**
     * 创建菜单
     */
    @Override
    public void createMenu() {
        Menu menu = null;
        ResultType resultType = null;
        try {
            InputStream in = FileUtils.openInputStream(new File(menuPath));
            menu = JSON.parseObject(in, Menu.class);
            resultType = menuAPI.createMenu(menu);
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println(resultType.toString());
    }

    @Autowired
    private MenuAPI menuAPI;

    @Value("${menu}")
    private String menuPath;
}
